﻿using System;
using UnityEngine;

public class AnimationEventFunction : MonoBehaviour
{
    public event Action startEvent;
    public event Action endEvent;
    public event Action damageEvent;
    public event Action stateChangedEvent;
    public event Action<string, Vector3, Vector3, Vector3> playEffectEvent;

    [Function]
    void OnStart(string arg)
    {
        if (startEvent == null)
            return;
        startEvent.Invoke();
    }
    [Function()]
    void OnEnd(string arg)
    {
        if (endEvent == null)
            return;
        endEvent.Invoke();
    }

    [Function]
    void OnDamage(string arg)
    {
        if (damageEvent == null)
            return;
        damageEvent.Invoke();
    }

    [Parameter("Path", "Position", "Rotation", "Scale")]
    [Function(typeof(string), typeof(Vector3), typeof(Vector3), typeof(Vector3))]
    void OnPlayEffect(string arg)
    {
        if (playEffectEvent == null)
            return;
        var fp = FunctionParameter.Create(arg);
        playEffectEvent.Invoke(fp[0].value, fp[1].ToVector3(), fp[2].ToVector3(), fp[3].ToVector3());
    }

    [Function]
    void OnStateChanged()
    {
        if (stateChangedEvent == null)
            return;

        stateChangedEvent.Invoke();
    }
}
